package com.xhwl.logistics.converter;

import com.xhwl.logistics.vo.VehicleCarVO;
import com.xhwl.logistics.vo.VehicleCardVO;
import com.xhwl.logistics.vo.VehicleRelationCarToCardVO;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

@Component
public class ToCarVO {

    public List<VehicleCarVO> toCompatibility(List<VehicleCarVO> vehicleCarVOList) {
        return vehicleCarVOList.stream().map(this::toCompatibility).collect(Collectors.toList());
    }

    public VehicleCarVO toCompatibility(VehicleCarVO vehicleCarVO) {
        VehicleCardVO vehicleCardVO = vehicleCarVO.getVehicleCardVO();
        if (Objects.isNull(vehicleCardVO)) {
            vehicleCarVO.setCardId(0);
            vehicleCarVO.setName("无");
        } else {
            Integer id = vehicleCardVO.getId();
            String name = vehicleCardVO.getName();
            vehicleCarVO.setCardId(id);
            vehicleCarVO.setName(name);

            VehicleRelationCarToCardVO vehicleRelationCarToCardVO = vehicleCarVO.getVehicleRelationCarToCardVO();
            if (Objects.nonNull(vehicleRelationCarToCardVO)) {
                Date validStartTime = vehicleRelationCarToCardVO.getValidStartTime();
                Date validEndTime = vehicleRelationCarToCardVO.getValidEndTime();

                vehicleCarVO.setValidStartTime(validStartTime);
                vehicleCarVO.setValidEndTime(validEndTime);
            }
        }
        return vehicleCarVO;
    }

}
